package com.antunnel.system.dao.impl;

import java.util.List;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import com.antunnel.common.orm.BaseDaoImpl;
import com.antunnel.system.dao.UserBaseDao;
import com.antunnel.system.entity.UserBase;

@Repository
public class UserBaseDaoImpl extends BaseDaoImpl implements UserBaseDao{

	public List<UserBase> loadUserByUserNameAndPsw(String loginCode, String loginPsw) throws Exception {
		String hql = " from UserBase u where username=? and password=?";
		Query query = getEntityManager().createQuery(hql);
		query.setParameter(1, loginCode);
		query.setParameter(2, loginPsw);
		List<UserBase> list = query.getResultList(); 
		return list;
	}

	/**
	 * 根据绑定的邮箱 ，绑定的银行，账号，开户人姓名查找用户
	 * @param email
	 * @param bankname 银行名称
	 * @param banknumber 银行卡号
	 * @param bankuser 所持账户姓名
	 * @param username 用户名
	 * @return
	 * @throws Exception
	 */
	public List<UserBase> loadUserByMsg(String email, String banknumber,
			String bankname, String bankuser, String username) throws Exception {
		String hql = " from UserBase u,UserBank b where u.id=b.userbase.id and u.username=? and u.email=? and b.bankname=? " +
				" and b.banknumber=? and b.bankuser=?";
		Query query = getEntityManager().createQuery(hql);
		query.setParameter(1, username);
		query.setParameter(2, email);
		query.setParameter(3, bankname);
		query.setParameter(4, banknumber);
		query.setParameter(5, bankuser);
		List<UserBase> list = query.getResultList(); 
		return list;
	}
}
